package net.lainiao.mycost.service.impl;

import net.lainiao.mycost.bean.RoleInfo;
import net.lainiao.mycost.dao.IRoleInfoDAO;
import net.lainiao.mycost.service.IRoleInfoService;
import net.lainiao.mycost.utils.Comm;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Administrator on 2017/3/22.
 */
@Service
@Transactional
public class RoleInfoServiceImpl implements IRoleInfoService {


    @Autowired
    private IRoleInfoDAO dao;

    @Override
    public void add(RoleInfo info) {
        dao.add(info);
    }

    @Override
    public void update(RoleInfo info) {
        dao.update(info);
    }

    private void condition(RoleInfo info) {
        if(info!=null){
            if(StringUtils.isNotEmpty(info.getRoleName())){
                info.setRoleName("%"+info.getRoleName()+"%");
            }
        }
    }

    @Override
    public void delete(Integer[] roleIds) {
        for(Integer roleId:roleIds){
            RoleInfo info=new RoleInfo();
            info.setRoleId(roleId);
            info.setRoleMark(Comm.MARK_NO);
            dao.update(info);
        }
    }

    @Override
    public List<RoleInfo> list(RoleInfo info) {
        condition(info);
        return dao.list(info);
    }

    @Override
    public long getCount(RoleInfo info) {
        condition(info);
        return dao.getCount(info);
    }

    @Override
    public RoleInfo getInfo(RoleInfo roleInfo) {
        return dao.getInfo(roleInfo);
    }
}
